home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / afv95.zip / VIDEO.CPP < prev    next >
Text File  |  1995-02-12  |  10KB  |  511 lines

  1. #include <bios.h>
  2. #include <ctype.h>
  3. #include <dos.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "video.h"
  8.  
  9. static void        Cursor(uchar x, uchar y);
  10. static int        Input(char *buf, uint size);
  11. static void        IWDraw(char *prompt);
  12. static void        IWRestore();
  13. static void        IWSave();
  14. static void        Print(uint y, char *line, uchar at);
  15. static void        RefLine(uint pline, uint lline);
  16. static void        SearchLine(uint *line);
  17.  
  18. static uint        atbord;
  19. static uint        atcurs;
  20. static uint        atscur;
  21. static uint        atsrch;
  22. static uint        atstxt;
  23. static uint        attext;
  24. static uint        datalcnt;
  25. static uint        datapara;
  26. static int        inpwind;
  27. static uchar    iwxpos;
  28. static uchar    iwypos;
  29. static uint        iwsav[2000];
  30. static uchar    iwxsiz;
  31. static uchar    iwysiz;
  32. static int        mono;
  33. static uint        savcur;
  34. static uint        savvid[2000];
  35. static char        srchtxt[81];
  36. static char        vbl79;
  37. static uint        vcuroff;
  38. static int        vidfnd;
  39. static uint        vidfndln;
  40. static uint        *vidram;
  41. static uint        vidrows;
  42.  
  43. void    Cursor(uchar x, uchar y)
  44. {
  45.     REGS    r;
  46.  
  47.     r.h.ah = 0x02;
  48.     r.h.bh = 0x00;
  49.     r.h.dh = y;
  50.     r.h.dl = x;
  51.     int86(0x10, &r, &r);
  52. }
  53.  
  54. uint    FndLine()
  55. {
  56.     return vidfndln;
  57. }
  58.  
  59. int    Input(char *buf, uint size)
  60. {
  61.     uchar    fx, fy, fw;
  62.     uint    voff;
  63.     int    x, curs, off;
  64.  
  65.     fx = iwxpos + 2;
  66.     fy = iwypos + 3;
  67.  
  68.     fw = size;
  69.  
  70.     if (fw > 60)
  71.         fw = 60;
  72.  
  73.     voff = fy * 80 + fx;
  74.  
  75.     for (x = 0 ; x < fw ; x++)
  76.         vidram[voff + x] = atsrch | ' ';
  77.  
  78.     curs    = 0;
  79.     off    = 0;
  80.  
  81.     buf[0] = 0;
  82.  
  83.     while (1)
  84.         {
  85.         uint    k;
  86.         char    *b;
  87.  
  88.         if (off > curs)
  89.             off = curs;
  90.         else if (off + fw < curs)
  91.             off = curs - fw;
  92.  
  93.         b = buf + off;
  94.  
  95.         for (x = 0 ; x < fw ; x++)
  96.             if (*b)
  97.                 vidram[voff + x] = atsrch | *b++;
  98.             else
  99.                 vidram[voff + x] = atsrch | ' ';
  100.  
  101.         Cursor(fx + curs - off, fy);
  102.  
  103.         k = bioskey(0);
  104.  
  105.         if (k & 0x00ff)
  106.             k &= 0x00ff;
  107.  
  108.         switch (k)
  109.             {
  110.             case 8:
  111.                 if (curs)
  112.                     buf[--curs] = 0;
  113.                 break;
  114.  
  115.             case '\n':
  116.             case '\r':
  117.                 return 1;
  118.  
  119.             case 27:
  120.                 return 0;
  121.  
  122.             default:
  123.                 if (k >= 0x20 && k <= 0x7f && curs < size)
  124.                     {
  125.                     buf[curs++] = k;
  126.                     buf[curs] = 0;
  127.                     }
  128.                 break;
  129.             }
  130.         }
  131. }
  132.  
  133. void    IWDraw(char *prompt)
  134. {
  135.     int    lx, rx, ty, by, cy, x, y, len;
  136.  
  137.     lx = iwxpos;
  138.     rx = iwxpos + iwxsiz - 1;
  139.     ty = iwypos;
  140.     by = iwypos + iwysiz - 1;
  141.     cy = iwypos + iwysiz / 2;
  142.  
  143.     for (y = ty ; y <= by ; y++)
  144.         for (x = lx ; x <= rx ; x++)
  145.             vidram[y * 80 + x] = attext | ' ';
  146.  
  147.     for (x = 1 ; x < iwxsiz - 1 ; x++)
  148.         {
  149.         vidram[ty * 80 + iwxpos + x] = attext | 205;
  150.         vidram[cy * 80 + iwxpos + x] = attext | 205;
  151.         vidram[by * 80 + iwxpos + x] = attext | 205;
  152.         }
  153.  
  154.     vidram[ty * 80 + lx] = attext | 201;
  155.     vidram[ty * 80 + rx] = attext | 187;
  156.     vidram[cy * 80 + lx] = attext | 204;
  157.     vidram[cy * 80 + rx] = attext | 185;
  158.     vidram[by * 80 + lx] = attext | 200;
  159.     vidram[by * 80 + rx] = attext | 188;
  160.  
  161.     vidram[(ty + 1) * 80 + lx] = attext | 186;
  162.     vidram[(ty + 1) * 80 + rx] = attext | 186;
  163.     vidram[(ty + 3) * 80 + lx] = attext | 186;
  164.     vidram[(ty + 3) * 80 + rx] = attext | 186;
  165.  
  166.     len = strlen(prompt);
  167.  
  168.     x = iwxpos + (iwxsiz - len) / 2;
  169.  
  170.     for (y = 0 ; prompt[y] ; y++)
  171.         vidram[(ty + 1) * 80 + x + y] = attext | prompt[y];
  172. }
  173.  
  174. void    IWRestore()
  175. {
  176.     uint    h, v;
  177.  
  178.     for (v = 0 ; v < iwysiz ; v++)
  179.         for (h = 0 ; h < iwxsiz ; h++)
  180.             {
  181.             uint    x, y;
  182.  
  183.             x = iwxpos + h;
  184.             y = iwypos + v;
  185.  
  186.             vidram[y * 80 + x] = iwsav[v * iwxsiz + h];
  187.             }
  188. }
  189.  
  190. void    IWSave()
  191. {
  192.     uint    h, v;
  193.  
  194.     for (v = 0 ; v < iwysiz ; v++)
  195.         for (h = 0 ; h < iwxsiz ; h++)
  196.             {
  197.             uint    x, y;
  198.  
  199.             x = iwxpos + h;
  200.             y = iwypos + v;
  201.  
  202.             iwsav[v * iwxsiz + h] = vidram[y * 80 + x];
  203.             }
  204. }
  205.  
  206. void    Print(uint y, char *text, uchar at)
  207. {
  208.     uint    x;
  209.  
  210.     for (x = 0 ; x < 80 ; x++)
  211.         if (*text)
  212.             vidram[y * 80 + x] = (uint(at) << 8) | *((uchar*)text++);
  213.         else 
  214.             vidram[y * 80 + x] = (uint(at) << 8) | 0x0020;
  215. }
  216.  
  217. void    RefLine(uint pline, uint lline)
  218. {
  219.     uchar    *ld;
  220.     uint    line[80], at;
  221.     int    x;
  222.  
  223.     if (lline < datalcnt)
  224.         {
  225.         ld = (uchar*)MK_FP(datapara + lline * 5, 0);
  226.  
  227.         if (pline == vcuroff + 1)
  228.             at = atcurs;
  229.         else if (ld[79] & 0x80)
  230.             at = atstxt;
  231.         else
  232.             at = attext;
  233.  
  234.         for (x = 0 ; x < 79 ; x++)
  235.             line[x] = at | ld[x];
  236.  
  237.         line[79] = at | ' ';
  238.  
  239.         if (srchtxt[0])
  240.             {
  241.             SearchLine(line);
  242.  
  243.             if (vidfnd && vidfndln == 0xffff)
  244.                 vidfndln = pline - 1;
  245.             }
  246.  
  247.         memcpy(vidram + pline * 80, line, sizeof(line));
  248.         }
  249.     else
  250.         for (x = 0 ; x < 80 ; x++)
  251.             vidram[pline * 80 + x] = attext | ' ';
  252. }
  253.  
  254. void    SearchLine(uint *line)
  255. {
  256.     int    x, fnd = 0;
  257.  
  258.     for (x = 0 ; x < 80 ; x++)
  259.         {
  260.         int    y;
  261.  
  262.         for (y = 0 ; srchtxt[y] ; y++)
  263.             if (toupper(line[x + y] & 0x00ff) != toupper(srchtxt[y]))
  264.                 break;
  265.  
  266.         if (!srchtxt[y])
  267.             {
  268.             vidfnd    = 1;
  269.             fnd        = 1;
  270.  
  271.             while (y--)
  272.                 line[x + y] = atsrch | (line[x + y] & 0x00ff);
  273.             }
  274.         }
  275.  
  276.     if (fnd)
  277.         for (x = 0 ; x < 80 ; x++)
  278.             if ((line[x] & 0xff00) == atcurs)
  279.                 line[x] = atscur | (line[x] & 0x00ff);
  280.             else if ((line[x] & 0xff00) == attext)
  281.                 line[x] = atstxt | (line[x] & 0x00ff);
  282. }
  283.  
  284. void    VidBL79(char c)
  285. {
  286.     vbl79 = c;
  287.  
  288.     if (c)
  289.         vidram[vidrows * 80 - 1] = atbord | c;
  290.     else 
  291.         vidram[vidrows * 80 - 1] = atbord | ' ';
  292. }
  293.  
  294. void    VidBotLine(char *text)
  295. {
  296.     uchar    *t = (uchar*)text;
  297.     uint    *vr;
  298.     int    c, x;
  299.  
  300.     vr = vidram + (vidrows - 1) * 80;
  301.  
  302.     c = (80 - strlen(text)) / 2;
  303.  
  304.     for (x = 0 ; x < 80 ; x++)
  305.         if (vbl79 && x == 79)
  306.             vr[x] = atbord | vbl79;
  307.         else if (x >= c && *t)
  308.             vr[x] = atbord | *t++;
  309.         else
  310.             vr[x] = atbord | ' ';
  311. }
  312.  
  313. void    VidCursor(uint cur)
  314. {
  315.     vcuroff = cur;
  316. }
  317.  
  318. void    VidDefData(uint base, uint lines)
  319. {
  320.     datapara = base;
  321.     datalcnt = lines;
  322. }
  323.  
  324. int    VidFound()
  325. {
  326.     return vidfnd;
  327. }
  328.  
  329. void    VidHelp()
  330. {
  331.     Print( 2, "╔══════════════════════════════════════════════════════════════════════════════╗", 0x3e);
  332.     Print( 3, "║ ESC           Quit AFView                                                    ║", 0x3e);
  333.     Print( 4, "║ ,           Move cursor line up and down                                   ║", 0x3e);
  334.     Print( 5, "║ PgUp, PgDn    Move up and down 1 page                                        ║", 0x3e);
  335.     Print( 6, "║ Home, End     Put cursor on top or bottom of screen                          ║", 0x3e);
  336.     Print( 7, "║ ^Home, ^End   Put cursor at top or bottom of list                            ║", 0x3e);
  337.     Print( 8, "║ Enter         Toggle between viewing directory list and a directory          ║", 0x3e);
  338.     Print( 9, "║ Alt S         Sort list                                                      ║", 0x3e);
  339.     Print(10, "║ F1            Display this screen                                            ║", 0x3e);
  340.     Print(11, "║ F5            Search for text                                                ║", 0x3e);
  341.     Print(12, "║ Shift F5      Search again                                                   ║", 0x3e);
  342.     Print(13, "╠══════════════════════════════════════════════════════════════════════════════╣", 0x3e);
  343.     Print(14, "║ This silly little program was written by Chris Sokol.  If you find this      ║", 0x3e);
  344.     Print(15, "║ program useful, good.  I don't want anything from you.  Some day a real      ║", 0x3e);
  345.     Print(16, "║ version of this program may be written.  If you have any suggestions or      ║", 0x3e);
  346.     Print(17, "║ comments, send mail to chris@infosafe.com.  I don't really check my IF mail  ║", 0x3e);
  347.     Print(18, "║ so it must go to the above address.                                          ║", 0x3e);
  348.     Print(19, "╠══════════════════════════════════════════════════════════════════════════════╣", 0x3e);
  349.     Print(20, "║ Oh, yeah.  This program is completely unsupported.  Sorry, no time for that. ║", 0x3e);
  350.     Print(21, "╚══════════════════════════════════════════════════════════════════════════════╝", 0x3e);
  351. }
  352.  
  353. void    VidInit(int font8x8)
  354. {
  355.     REGS    r;
  356.  
  357.     r.h.ah = 0x0f;
  358.     int86(0x10, &r, &r);
  359.  
  360.     if (r.h.al == 0x07)
  361.         {
  362.         vidram = (uint*)0xb0000000;
  363.         mono = 1;
  364.         }
  365.     else if (r.h.al == 0x03)
  366.         {
  367.         vidram = (uint*)0xb8000000;
  368.         mono = 0;
  369.         }
  370.     else
  371.         {
  372.         fprintf(stderr, "Program must be started in 80 column text mode.\n");
  373.         exit(1);
  374.         }
  375.  
  376.     memcpy(savvid, vidram, sizeof(savvid));
  377.  
  378.     r.h.ah = 0x03;
  379.     r.h.bh = 0x00;
  380.     int86(0x10, &r, &r);
  381.  
  382.     savcur = r.x.dx;
  383.  
  384.     if (!mono && font8x8)
  385.         {
  386.         r.x.ax = 0x0003;
  387.         int86(0x10, &r, &r);
  388.  
  389.         r.x.ax = 0x1112;
  390.         r.h.bl = 0x00;
  391.         int86(0x10, &r, &r);
  392.  
  393.         r.x.ax = 0x1130;
  394.         r.h.bh = 0x00;
  395.         r.h.dl = 25;
  396.         int86(0x10, &r, &r);
  397.  
  398.         vidrows = r.h.dl;
  399.         }
  400.     else
  401.         vidrows = 25;
  402.  
  403.     Cursor(80, vidrows);
  404.  
  405.     if (mono)
  406.         {
  407.         atbord = 0x7f00;
  408.         atcurs = 0x7000;
  409.         atscur = 0x7000;
  410.         atsrch = 0x7f00;
  411.         atstxt = 0x0f00;
  412.         attext = 0x0700;
  413.         }
  414.     else 
  415.         {
  416.         atbord = 0x4e00;
  417.         atcurs = 0x2f00;
  418.         atscur = 0x2f00;
  419.         atsrch = 0x4f00;
  420.         atstxt = 0x1f00;
  421.         attext = 0x1e00;
  422.         }
  423. }
  424.  
  425. int    VidInput(char *prompt, char *buf, uint size)
  426. {
  427.     int    len, stat;
  428.  
  429.     len = strlen(prompt);
  430.  
  431.     if (size > len)
  432.         len = size;
  433.  
  434.     iwxsiz = (len < 60) ? (len + 4) : (64);
  435.     iwysiz = 5;
  436.  
  437.     iwxpos = (80 - iwxsiz) / 2;
  438.     iwypos = (vidrows - iwysiz) / 2;
  439.  
  440.     IWSave();
  441.  
  442.     IWDraw(prompt);
  443.  
  444.     stat = Input(buf, size);
  445.  
  446.     IWRestore();
  447.  
  448.     Cursor(80, vidrows);
  449.  
  450.     return stat;
  451. }
  452.  
  453. void    VidRefresh(uint topline)
  454. {
  455.     int    y;
  456.  
  457.     vidfnd    = 0;
  458.     vidfndln    = 0xffff;
  459.  
  460.     for (y = 1 ; y < vidrows - 1 ; y++)
  461.         RefLine(y, topline + y - 1);
  462. }
  463.  
  464. uint    VidRows()
  465. {
  466.     return vidrows;
  467. }
  468.  
  469. void    VidSearch(char *text)
  470. {
  471.     if (text)
  472.         {
  473.         memcpy(srchtxt, text, 80);
  474.         srchtxt[80] = 0;
  475.         }
  476.     else
  477.         srchtxt[0] = 0;
  478. }
  479.  
  480. void    VidTerm()
  481. {
  482.     REGS    r;
  483.  
  484.     if (vidrows != 25)
  485.         {
  486.         r.x.ax = 0x0003;
  487.         int86(0x10, &r, &r);
  488.         }
  489.  
  490.     memcpy(vidram, savvid, sizeof(savvid));
  491.  
  492.     r.h.ah = 0x02;
  493.     r.h.bh = 0x00;
  494.     r.x.dx = savcur;
  495.     int86(0x10, &r, &r);
  496. }
  497.  
  498. void    VidTopLine(char *text)
  499. {
  500.     uchar    *t = (uchar*)text;
  501.     int    c, x;
  502.  
  503.     c = (80 - strlen(text)) / 2;
  504.  
  505.     for (x = 0 ; x < 80 ; x++)
  506.         if (x >= c && *t)
  507.             vidram[x] = atbord | *t++;
  508.         else
  509.             vidram[x] = atbord | ' ';
  510. }
  511.